package com.own.demo.lwf.utils.javaUtils;

// import io.swagger.annotations.ApiModel;
// import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author liwenfeng
 * @Description  统一结果返回类
 * @Date 2023/07/07/16:07
 * @Version 1.0
 */
@Data
@Accessors(chain = true)
// @ApiModel(value = "统一结果返回类")
public class ResponseEntity {
    // @ApiModelProperty(value = "是否成功")
    private Boolean success;

    // @ApiModelProperty(value = "状态码")
    private Integer code;

    // @ApiModelProperty(value = "返回消息")
    private String msg;

    // @ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<>();

    private ResponseEntity() {}

    public static ResponseEntity ok() {
        return new ResponseEntity()
                .setSuccess(true)
                // .setCode(ResultCode.SUCCESS_CODE)
                .setMsg("成功");
    }

    public static ResponseEntity error() {
        return new ResponseEntity()
                .setSuccess(false)
                // .setCode(ResultCode.FAIL_CODE)
                .setMsg("失败");
    }

    //    链式编程
    public ResponseEntity success(Boolean success) {
        this.setSuccess(success);
        return this;
    }
    public ResponseEntity code(Integer code) {
        this.setCode(code);
        return this;
    }
    public ResponseEntity msg(String msg) {
        this.setMsg(msg);
        return this;
    }
    public ResponseEntity data(String key, Object val) {
        this.data.put(key, val);
        return this;
    }
}
